home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / print / 890ps.arc / NETWARE.C < prev    next >
Text File  |  1989-12-31  |  11KB  |  637 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <dos.h>
  4.  
  5. #ifdef __OS2_MT__
  6. #include <process.h>
  7. #endif
  8.  
  9. #include <netware.h>
  10.  
  11.  
  12. #define swap(val)      ((val<<8)+(val>>8))
  13. #define swapd(val)     ((val<<24)+((val&0xFF00)<<8)+((val&0xFF0000L)>>8)+(val>>24))
  14. #define initbuf(buf)   memset(&buf,0,sizeof(buf));buf._len = sizeof(buf)-sizeof(buf._len)  /*  initialize buffer length  */
  15.  
  16.  
  17. byte NetWare(word func, void *req, void *rep)
  18. {
  19.   union REGS i_reg,o_reg;
  20.   struct SREGS sreg;
  21.  
  22.   i_reg.h.ah = func;
  23.   i_reg.x.si = FP_OFF(req);
  24.   i_reg.x.di = FP_OFF(rep);
  25. #if (defined M_I86SM) | (defined M_I86MM)
  26.   sreg.ds = _DS;
  27.   sreg.es = _ES;
  28. #else
  29.   sreg.ds = FP_SEG(req);
  30.   sreg.es = FP_SEG(rep);
  31. #endif
  32.  
  33. #ifdef __OS2_MT__
  34.   Lock();
  35. #endif
  36.   int86x(0x21,&i_reg,&o_reg,&sreg);
  37. #ifdef __OS2_MT__
  38.   Unlock();
  39. #endif
  40.  
  41.   return(o_reg.h.al);
  42. }
  43.  
  44.  
  45. byte ChangeBinderyObjectPassword(const char *name, word type,
  46.                                  const char *oldpass, const char *newpass)
  47. {
  48.   struct {
  49.     word _len;
  50.     byte _func;
  51.     word _type;
  52.     byte _namelen;
  53.     char _name[OBJNAMEMAXLEN];
  54.     byte _oldpasslen;
  55.     char _oldpass[OBJPASSMAXLEN];
  56.     byte _newpasslen;
  57.     char _newpass[OBJPASSMAXLEN];
  58.   } req;
  59.   struct {
  60.     word _len;
  61.   } rep;
  62.  
  63.   initbuf(req);
  64.   initbuf(rep);
  65.  
  66.   req._func = 0x40;
  67.   req._type = swap(type);
  68.   req._namelen = OBJNAMEMAXLEN;
  69.   strcpy(req._name,name);
  70.   req._oldpasslen = OBJPASSMAXLEN;
  71.   strcpy(req._oldpass,oldpass);
  72.   req._newpasslen = OBJPASSMAXLEN;
  73.   strcpy(req._newpass,newpass);
  74.  
  75.   return(NetWare(0xE3,&req,&rep));
  76. }
  77.  
  78.  
  79. byte DeleteBinderyObject(const char *name, word type)
  80. {
  81.   struct {
  82.     word _len;
  83.     byte _func;
  84.     word _type;
  85.     byte _namelen;
  86.     char _name[OBJNAMEMAXLEN];
  87.   } req;
  88.   struct {
  89.     word _len;
  90.   } rep;
  91.  
  92.   initbuf(req);
  93.   initbuf(rep);
  94.  
  95.   req._func = 0x33;
  96.   req._type = swap(type);
  97.   req._namelen = OBJNAMEMAXLEN;
  98.   strcpy(req._name,name);
  99.  
  100.   return(NetWare(0xE3,&req,&rep));
  101. }
  102.  
  103.  
  104. byte CreateBinderyObject(const char *name, word type, const char *password,
  105.                          byte security, byte flags)
  106. {
  107.   struct {
  108.     word _len;
  109.     byte _func;
  110.     byte _flags;
  111.     byte _security;
  112.     word _type;
  113.     byte _namelen;
  114.     char _name[OBJNAMEMAXLEN];
  115.   } req;
  116.   struct {
  117.     word _len;
  118.   } rep;
  119.   word res;
  120.  
  121.   initbuf(req);
  122.   initbuf(rep);
  123.  
  124.   req._func = 0x32;
  125.   req._flags = flags;
  126.   req._security = security;
  127.   req._type = swap(type);
  128.   req._namelen = OBJNAMEMAXLEN;
  129.   strcpy(req._name,name);
  130.  
  131.   res = NetWare(0xE3,&req,&rep);
  132.   if ((res==0) && (strlen(password)!=0)) {
  133.     if ((res=ChangeBinderyObjectPassword(name,type,"",password))!=0) {
  134.       DeleteBinderyObject(name,type);
  135.     };
  136.   };
  137.  
  138.   return(res);
  139. }
  140.  
  141.  
  142. byte LoginToFileServer(const char *name, word type, const char *password)
  143. {
  144.   struct {
  145.     word _len;
  146.     byte _func;
  147.     word _type;
  148.     byte _namelen;
  149.     char _name[OBJNAMEMAXLEN];
  150.     byte _passwordlen;
  151.     char _password[OBJPASSMAXLEN];
  152.   } req;
  153.   struct {
  154.     word _len;
  155.   } rep;
  156.  
  157.   initbuf(req);
  158.   initbuf(rep);
  159.  
  160.   req._func = 0x14;
  161.   req._type = swap(type);
  162.   req._namelen = OBJNAMEMAXLEN;
  163.   strcpy(req._name,name);
  164.   req._passwordlen = OBJPASSMAXLEN;
  165.   strcpy(req._password,password);
  166.  
  167.   return(NetWare(0xE3,&req,&rep));
  168. }
  169.  
  170.  
  171. byte CreateQueue(const char *name, word type, byte dir, const char *path,
  172.                  dword *id)
  173. {
  174.   struct {
  175.     word _len;
  176.     byte _func;
  177.     word _type;
  178.     byte _namelen;
  179.     char _name[OBJNAMEMAXLEN];
  180.     byte _dir;
  181.     byte _pathlen;
  182.     char _path[118];
  183.   } req;
  184.   struct {
  185.     word _len;
  186.     dword _id;
  187.   } rep;
  188.   byte res;
  189.  
  190.   initbuf(req);
  191.   initbuf(rep);
  192.  
  193.   req._func = 0x64;
  194.   req._type = swap(type);
  195.   req._namelen = OBJNAMEMAXLEN;
  196.   strcpy(req._name,name);
  197.   req._dir = dir;
  198.   req._pathlen = 118;
  199.   strcpy(req._path,path);
  200.  
  201.   res = NetWare(0xE3,&req,&rep);
  202.  
  203.   if (id!=NULL) {
  204.     *id = swapd(rep._id);
  205.   }
  206.  
  207.   return(res);
  208. }
  209.  
  210.  
  211. byte AllocPermanentDirectoryHandle(char drive, byte dir, const char *path,
  212.                                    byte *handle, byte *rights)
  213. {
  214.   struct {
  215.     word _len;
  216.     byte _func;
  217.     byte _dir;
  218.     byte _drive;
  219.     byte _pathlen;
  220.     char _path[255];
  221.   } req;
  222.   struct {
  223.     word _len;
  224.     byte _handle;
  225.     byte _rights;
  226.   } rep;
  227.   byte res;
  228.  
  229.   initbuf(req);
  230.   initbuf(rep);
  231.  
  232.   req._func = 0x12;
  233.   req._dir = dir;
  234.   req._drive = drive;
  235.   req._pathlen = 255;
  236.   strcpy(req._path,path);
  237.  
  238.   res=NetWare(0xE2,&req,&rep);
  239.   if (handle!=NULL) {
  240.     *handle = rep._handle;
  241.   }
  242.   if (rights!=NULL) {
  243.     *rights = rep._rights;
  244.   }
  245.  
  246.   return res;
  247. }
  248.  
  249.  
  250. byte EnterLoginArea(byte locals, const char *path)
  251. {
  252.   struct {
  253.     word _len;
  254.     byte _func;
  255.     byte _locals;
  256.     byte _pathlen;
  257.     char _path[255];
  258.   } req;
  259.   struct {
  260.     word _len;
  261.   } rep;
  262.  
  263.   initbuf(req);
  264.   initbuf(rep);
  265.  
  266.   req._func = 0x0A;
  267.   req._locals = locals;
  268.   req._pathlen = 255;
  269.   strcpy(req._path,path);
  270.  
  271.   return NetWare(0xE3,&req,&rep);
  272. }
  273.  
  274.  
  275. byte GetBinderyObjectID(const char *name, word type, dword *id)
  276. {
  277.   struct {
  278.     word _len;
  279.     byte _func;
  280.     word _type;
  281.     byte _namelen;
  282.     char _name[OBJNAMEMAXLEN];
  283.   } req;
  284.   struct {
  285.     word _len;
  286.     dword _id;
  287.     word _type;
  288.     char _name[OBJNAMEMAXLEN+1];
  289.   } rep;
  290.   byte res;
  291.  
  292.   initbuf(req);
  293.   initbuf(rep);
  294.  
  295.   req._func = 0x35;
  296.   req._type = swap(type);
  297.   req._namelen = OBJNAMEMAXLEN;
  298.   strcpy(req._name,name);
  299.  
  300.   res=NetWare(0xE3,&req,&rep);
  301.   if (id!=NULL) {
  302.     *id = swapd(rep._id);
  303.   }
  304.  
  305.   return(res);
  306. }
  307.  
  308.  
  309. byte AttachQueueServerToQueue(dword id)
  310. {
  311.   struct {
  312.     word _len;
  313.     byte _func;
  314.     dword _id;
  315.   } req;
  316.   struct {
  317.     word _len;
  318.   } rep;
  319.  
  320.   initbuf(req);
  321.   initbuf(rep);
  322.  
  323.   req._func = 0x6F;
  324.   req._id = swapd(id);
  325.  
  326.   return(NetWare(0xE3,&req,&rep));
  327. }
  328.  
  329.  
  330. byte DetachQueueServerFromQueue(dword id)
  331. {
  332.   struct {
  333.     word _len;
  334.     byte _func;
  335.     dword _id;
  336.   } req;
  337.   struct {
  338.     word _len;
  339.   } rep;
  340.  
  341.   initbuf(req);
  342.   initbuf(rep);
  343.  
  344.   req._func = 0x70;
  345.   req._id = swapd(id);
  346.  
  347.   return(NetWare(0xE3,&req,&rep));
  348. }
  349.  
  350.  
  351. void ConvertJobInfo(QueueJobInfoStruct *out, const QueueJobInfoStruct *in)
  352. {
  353.   if ((out!=NULL) && (in!=NULL)) {
  354.     memcpy(out,in,sizeof(QueueJobInfoStruct));
  355.     out->_ClientID = swapd(in->_ClientID);
  356.     out->_TargetID = swapd(in->_TargetID);
  357.     out->_JobNumber = swap(in->_JobNumber);
  358.     out->_JobType = swap(out->_JobType);
  359.     out->_ServerID = swapd(out->_ServerID);
  360.   }
  361. }
  362.  
  363.  
  364. byte ServiceQueueJobAndOpenFile(dword id, word type,
  365.                                 QueueJobInfoStruct *info)
  366. {
  367.   struct {
  368.     word _len;
  369.     byte _func;
  370.     dword _id;
  371.     word _type;
  372.   } req;
  373.   struct {
  374.     word _len;
  375.     QueueJobInfoStruct _info;
  376.   } rep;
  377.   byte res;
  378.  
  379.   initbuf(req);
  380.   initbuf(rep);
  381.  
  382.   req._func = 0x71;
  383.   req._id = swapd(id);
  384.   req._type = swap(type);
  385.  
  386.   res=NetWare(0xE3,&req,&rep);
  387.   ConvertJobInfo(info,&rep._info);
  388.  
  389.   return(res);
  390. }
  391.  
  392.  
  393. byte FinishServicingQueueJobAndFile(dword id, word job, dword charge)
  394. {
  395.   struct {
  396.     word _len;
  397.     byte _func;
  398.     dword _id;
  399.     word _job;
  400.     dword _charge;
  401.   } req;
  402.   struct {
  403.     word _len;
  404.   } rep;
  405.  
  406.   initbuf(req);
  407.   initbuf(rep);
  408.  
  409.   req._func = 0x72;
  410.   req._id = swapd(id);
  411.   req._job = swap(job);
  412.   req._charge = swapd(charge);
  413.  
  414.   return(NetWare(0xE3,&req,&rep));
  415. }
  416.  
  417.  
  418. byte ReadQueueCurrentStatus(dword id, byte *status, byte *jobs, byte *servers,
  419.                             dword sid[], byte stations[], byte *mserver)
  420. {
  421.   struct {
  422.     word _len;
  423.     byte _func;
  424.     dword _id;
  425.   } req;
  426.   struct {
  427.     word _len;
  428.     dword _id;
  429.     byte _status;
  430.     byte _jobs;
  431.     byte _servers;
  432.     dword _sid[25];
  433.     byte _stations[25];
  434.     byte _mserver;
  435.   } rep;
  436.   byte res;
  437.  
  438.   initbuf(req);
  439.   initbuf(rep);
  440.  
  441.   req._func = 0x66;
  442.   req._id = swapd(id);
  443.  
  444.   res=NetWare(0xE3,&req,&rep);
  445.   if (status!=NULL) {
  446.     *status = rep._status;
  447.   }
  448.   if (jobs!=NULL) {
  449.     *jobs = rep._jobs;
  450.   }
  451.   if (servers!=NULL) {
  452.     *servers = rep._servers;
  453.   }
  454.   if (sid!=NULL) {
  455.     for (res=0;res<25;res++) {
  456.       sid[res] = swapd(rep._sid[res]);
  457.     }
  458.     res = 0;
  459.   }
  460.   if (stations!=NULL) {
  461.     for (res=0;res<25;res++) {
  462.       stations[res] = rep._stations[res];
  463.     }
  464.     res = 0;
  465.   }
  466.   if (mserver!=NULL) {
  467.     *mserver = rep._mserver;
  468.   }
  469.  
  470.   return(res);
  471. }
  472.  
  473.  
  474. byte AbortServicingQueueJobAndFile(dword id, word job)
  475. {
  476.   struct {
  477.     word _len;
  478.     byte _func;
  479.     dword _id;
  480.     word _job;
  481.   } req;
  482.   struct {
  483.     word _len;
  484.   } rep;
  485.  
  486.   initbuf(req);
  487.   initbuf(rep);
  488.  
  489.   req._func = 0x73;
  490.   req._id = swapd(id);
  491.   req._job = swap(job);
  492.  
  493.   return(NetWare(0xE3,&req,&rep));
  494. }
  495.  
  496.  
  497. byte Logout(void)
  498. {
  499.   union REGS i_regs, o_regs;
  500.  
  501.   i_regs.h.ah = 0xD7;
  502.  
  503. #ifdef __OS2_MT__
  504.   Lock();
  505. #endif
  506.   int86(0x21,&i_regs,&o_regs);
  507. #ifdef __OS2_MT__
  508.   Unlock();
  509. #endif
  510.  
  511.   return(0);
  512. }
  513.  
  514.  
  515. byte ReadQueueJobEntry(dword id, word job, QueueJobInfoStruct *info,
  516.                        char jdesc[], byte client[])
  517. {
  518.   struct {
  519.     word _len;
  520.     byte _func;
  521.     dword _id;
  522.     word _job;
  523.   } req;
  524.   struct {
  525.     word _len;
  526.     QueueJobInfoStruct _info;
  527.     char _jdesc[50];
  528.     byte _client[152];
  529.   } rep;
  530.   byte res;
  531.  
  532.   initbuf(req);
  533.   initbuf(rep);
  534.  
  535.   req._func = 0x6C;
  536.   req._id = swapd(id);
  537.   req._job = swap(job);
  538.  
  539.   res=NetWare(0xE3,&req,&rep);
  540.   ConvertJobInfo(info,&rep._info);
  541.   if (jdesc!=NULL) {
  542.     memcpy(jdesc,&rep._jdesc,sizeof(rep._jdesc));
  543.   }
  544.   if (client!=NULL) {
  545.     memcpy(client,&rep._client,sizeof(rep._client));
  546.   }
  547.  
  548.   return(res);
  549. }
  550.  
  551.  
  552. byte ReadPrintJobInfo(dword id, word job, PrintJobClientStruct *client)
  553. {
  554.   byte res;
  555.  
  556.   res=ReadQueueJobEntry(id,job,NULL,NULL,(byte *) client);
  557.   if (client!=NULL) {
  558.     client->_Copies = swap(client->_Copies);
  559.     client->_Flags = swap(client->_Flags);
  560.     client->_Lines = swap(client->_Lines);
  561.     client->_Chars = swap(client->_Chars);
  562.   }
  563.  
  564.   return(res);
  565. }
  566.  
  567.  
  568. byte GetQueueJobList(dword id, word *count, word jobs[], word *max)
  569. {
  570.   struct {
  571.     word _len;
  572.     byte _func;
  573.     dword _id;
  574.   } req;
  575.   struct {
  576.     word _len;
  577.     word _count;
  578.     word _jobs[250];
  579.     word _max;
  580.   } rep;
  581.   byte res;
  582.  
  583.   initbuf(req);
  584.   initbuf(rep);
  585.  
  586.   req._func = 0x6B;
  587.   req._id = swapd(id);
  588.  
  589.   res=NetWare(0xE3,&req,&rep);
  590.   if (count!=NULL) {
  591.     *count = swap(rep._count);
  592.   }
  593.   if (jobs!=NULL) {
  594.     for (res=0;res<250;res++) {
  595.       jobs[res] = swap(rep._jobs[res]);
  596.     }
  597.     res = 0;
  598.   }
  599.   if (max!=NULL) {
  600.     *max = swap(rep._max);
  601.   }
  602.  
  603.   return(res);
  604. }
  605.  
  606.  
  607. byte GetQueueJobsFileSize(dword id, word job, dword *size)
  608. {
  609.   struct {
  610.     word _len;
  611.     byte _func;
  612.     dword _id;
  613.     word _job;
  614.   } req;
  615.   struct {
  616.     word _len;
  617.     dword _id;
  618.     word _job;
  619.     dword _size;
  620.   } rep;
  621.   byte res;
  622.  
  623.   initbuf(req);
  624.   initbuf(rep);
  625.  
  626.   req._func = 0x78;
  627.   req._id = swapd(id);
  628.   req._job = swap(job);
  629.  
  630.   res=NetWare(0xE3,&req,&rep);
  631.   if (size!=NULL) {
  632.     *size = swapd(rep._size);
  633.   }
  634.  
  635.   return(res);
  636. }
  637.